<?php
/**
 * 系统参数设置
 * Created by PhpStorm.
 * User: andy
 * Date: 2019/9/11
 * Time: 下午6:34
 */

namespace app\control\controller;

use app\common\model\WebConfigModel;
use think\facade\Config;
use think\facade\Request;

class SystemController extends AdminBaseController
{
    /**
     * 设置
     */
    public function index(){
        $menu=Config::get("WEB_SET_CAT");

        $this->assign("menu",$menu);
        return $this->fetch();
    }

    /**
     * 获取数据
     * @param int $cat_id
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function ajax_option($cat_id=0){
        $list=WebConfigModel::where('cat_id',$cat_id)
            ->order(['list_order' => 'asc', 'create_time' => 'asc'])
            ->select();

        $this->assign('option',$list);
        return $this->fetch();
    }

    /**
     * 编辑
     * @param int $id
     * @param int $pid
     * @return mixed
     */
    public function edit(){
        $data=Request::param();

        foreach ($data as $key=>$vo) {
            if(!empty($vo) && $vo!=""){
                $wc=WebConfigModel::where('name',$key)->find();
                $wc->value=$vo;
                $wc->save();
            }
        }

        WebConfigModel::getPublicConfig(true);

        $this->success('操作成功！');
    }
}